package cn.edu.zbu.pojo;

import java.util.List;

public class PageBean {
    private List<Car> list;//页面显示需要的数据
    private int currentPage=1;//当前页
    private int previous;//前一页
    private int next;//下一页
    private int totalCount;//总记录数
    private int totalPage;//总页数
    private int rows=10;//每页显示的记录数
    private int begin;//开始页
    private int end;//结束页
    public PageBean() {
    }
    public PageBean(int currentPage,int rows,int totalCount, List<Car> list) {
        this.currentPage=currentPage;
        this.rows=rows;
        this.totalCount = totalCount;
        this.list = list;
        getBeginEnd();
//        getTotalpage();//与totalCount和rows有关
//        getPreviouspage();//与currentPage有关
//        getNextpage();//与currentPage和totalPage有关
//        getPagebar();//与totalPage有关，这个要先计算

    }

    public List<Car> getList() {
        return list;
    }

    public void setList(List<Car> list) {
        this.list = list;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getPrevious() {
        if(this.currentPage-1>1){
            this.previous = this.currentPage-1;
        }else{
            this.previous = 1;
        }
        return previous;
    }

    public void setPrevious(int previous) {
        this.previous = previous;
    }

    public int getNext() {
        if(this.currentPage+1>this.totalPage){
            this.next = this.totalPage;
        }else{
            this.next = this.currentPage+1;
        }
        return next;
    }

    public void setNext(int next) {
        this.next = next;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getTotalPage() {
        //System.out.println("gettotalpage"+totalPage);
        if(this.totalCount%this.rows==0){
            this.totalPage = this.totalCount/this.rows;
        }else{
            this.totalPage = this.totalCount/this.rows + 1;
        }
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getRows() {
        return rows;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }

    public int getBegin() {
        return begin;
    }
    public int getEnd() {
        return end;
    }
    public void getBeginEnd() {
        if(this.getTotalPage()<=10){//应该先计算一下总页数，再计算页码条
            begin = 1;
            end = this.totalPage;//总共不足10页，以实际为准
        }else{
            begin = this.currentPage -5;//当前面放在中间来规划开始与结束页码条
            end = this.currentPage + 4;
            if(begin<1){//currentpage=2;startpage不能为-2，修正为1
                begin = 1;
                end = 10;
            }
            if(end>totalPage){//处理当前页加5大于总页数的情况
                end = totalPage;
                begin = totalPage -9;
            }
        }
    }
}
